/**
 * @param {number[]} nums
 * @return {number}
 */
var missingNumber = function (nums) {
  let len = nums.length;
  let left = 0;
  let right = len - 1;
  while (left <= right) {
    let middle = left + Math.floor((right - left) / 2);
    if (nums[middle] == middle) {
      left = middle + 1;
    } else {
      right = middle - 1;
    }
  }
  return left;
};
